[contents] [prev] [next] [top] [bottom] (3 out of 12)

Types of Expression

A ScriptX program is a sequence of ScriptX expressions. Every complete construct in the ScriptX language is an expression. Every expression yields a value that is an object, and every object is an instance of a class, either a class that is defined by the environment, or one that is created by the user.

A sentence is the basic unit of syntax that is evaluated incrementally by the ScriptX bytecode compiler, generally a single top-level expression followed by an end-of-line character.

sentence	::=	[ endOfLine ]* sentence 
	|	topLevelExpr endOfStream 
	|	topLevelExpr endOfLine 
	|	endOfStream 

An expression that can be entered and evaluated at the top level, outside of any blocks, is a top-level expression. An expression that can be entered and evaluated inside a compound expression, that is, within parentheses, is an inner-level expression. A few operations are permitted only at one level. For example, modules can only be defined at the top level, and locals can only be declared as inner-level expressions. Most ScriptX expressions are allowed at both levels.

topLevelExpr	::=	simpleExpr 
	|	globalExpr 
	|	guardExpr 
	|	assignmentExpr 
	|	repeatExpr 
	|	moduleExpr 
	|	inModuleExpr 
innerLevelExpr	::=	expr 
	|	localExpr 

Expressions are a subcategory of inner-level expressions, a general category to which most other ScriptX expressions belong.

expr	::=	simpleExpr 
	|	guardExpr 
	|	assignmentExpr 
	|	repeatExpr 
	|	blockControlExpr 

In ScriptX, the target of a control structure is generally an expression. Examples are the if . . . then and guard constructs.

ifExpr	::=	if simpleExpr then expr else expr 
	|	if simpleExpr do expr 
	|	if simpleExpr then expr 
guardExpr	::=	guard expr [ catching catchList ] [ on exit expr ] end 

A simple expression is a subcategory of both expression and top-level expression. An expression that forms a clause within another expression must be a simple expression.

simpleExpr	::=	factor 
	|	ifExpr 
	|	caseExpr 
	|	forExpr 
	|	classDefExpr 
	|	objectDefExpr 
	|	functionDefExpr 
	|	callExpr 
	|	coercionExpr 
	|	pipeExpr 
	|	threadExpr 
	|	arithmeticExpr 
	|	rangeLiteral 

A factor is a subcategory of simple expression. Factors are expressions, such as literals, that are indivisible units of syntax, units that usually cannot be factored into smaller units. A factor is the smallest possible piece of an expression that is itself an expression.

Any expression that is enclosed in parentheses, including a compound expression or an anonymous function, is a special kind of factor. In the surrounding scope, an expression enclosed in parentheses is recognized as a factor. This allows any inner-level expression to be used where a factor is required. Because of the precedence of factors, parentheses provide classical control over evaluation order.

ScriptX includes two special constructs that behave as factors. The nextMethod construct, which must appear within the body of a method, denotes the method you are in. Its prime use is for calling superclass methods. The question mark ( ? ) is a special construct that always stands for the most recent value returned at the top level by the scripter. As a consequence, it makes sense only in scripts that are evaluated in a listener window.

factor	::=	location 
	|	numbericConstant 
	|	stringLiteral 
	|	nameLiteral 
	|	? 
	|	nextMethod 
	|	anonFuncDefExpr 
	|	compoundExpr 	
	|	arrayLiteral 

Figure A-1 demonstrates how top-level and inner-level expressions can be broken out into one of the five grammatical categories defined here: top-level expressions, inner-level expressions, expressions, simple expressions, and factors. These categories are used throughout the grammar to establish rules of syntax.

Figure A-1: Types of ScriptX expressions


This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.

Copyright 1996 Apple Computer, Inc. All Rights Reserved.